#pragma once
#include "mkvmuxpin.hpp"

namespace MkvMux
{

class MkvStream;

class Inpin : public Pin, public IMemInputPin
{
    Inpin(const Inpin&);
    Inpin& operator=(const Inpin&);
    
protected:
    
    Inpin(Filter*, const wchar_t*);
    //virtual ~Inpin();
    
public:

    void Init();
    //virtual void Final() = 0;

    //IUnknown interface:
    
    HRESULT STDMETHODCALLTYPE QueryInterface(const IID&, void**);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();
    
    //IPin interface:

    HRESULT STDMETHODCALLTYPE Connect(IPin*, const AM_MEDIA_TYPE*);

    //HRESULT STDMETHODCALLTYPE Disconnect();

    HRESULT STDMETHODCALLTYPE ReceiveConnection( 
        IPin*,
        const AM_MEDIA_TYPE*);
        
    HRESULT STDMETHODCALLTYPE QueryInternalConnections( 
        IPin**,
        ULONG*);
        
    HRESULT STDMETHODCALLTYPE EndOfStream();

    HRESULT STDMETHODCALLTYPE BeginFlush();    

    HRESULT STDMETHODCALLTYPE EndFlush();
    
    HRESULT STDMETHODCALLTYPE NewSegment( 
        REFERENCE_TIME,
        REFERENCE_TIME,
        double);
        
    //IMemInputPin
    
    HRESULT STDMETHODCALLTYPE GetAllocator(
        IMemAllocator**);
    
    HRESULT STDMETHODCALLTYPE NotifyAllocator( 
        IMemAllocator*,
        BOOL);
    
    //HRESULT STDMETHODCALLTYPE GetAllocatorRequirements( 
    //    ALLOCATOR_PROPERTIES*);

    HRESULT STDMETHODCALLTYPE Receive(IMediaSample*);    
    
    HRESULT STDMETHODCALLTYPE ReceiveMultiple( 
        IMediaSample**,
        long,
        long*);
    
    HRESULT STDMETHODCALLTYPE ReceiveCanBlock();

protected:

   virtual HRESULT OnReceiveConnection(IPin*, const AM_MEDIA_TYPE&);
   virtual HRESULT OnReceive(IMediaSample*);
   virtual HRESULT OnEndOfStream();
   virtual HRESULT OnReceiveMultiple(IMediaSample* const*, long, long&);
    
private:

   bool m_bEndOfStream;
   bool m_bFlush;
    
protected:

   MkvStream* m_pStream;
   virtual HRESULT OnInit() = 0;
   //virtual HRESULT OnFinal() = 0;
        
};
    
}  //end namespace MkvMux

